package com.feri.redromance01.service.impl;


import com.feri.redromance01.dao.VipDao;

import com.feri.redromance01.entity.Vip;

import com.feri.redromance01.service.intf.VipService;
import com.feri.redromance01.util.StringUtil;
import com.feri.redromance01.vo.PageBean;
import com.feri.redromance01.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VipServiceImpl implements VipService {
    @Autowired
    private VipDao dao;


    @Override
    public R save(Vip vip) {
        if (dao.save(vip)>0){
            return R.ok();
        }else{
            return R.fail();
        }
    }

    @Override
    public R update(Vip vip) {
        if (dao.update(vip)>0){
            return R.ok();
        }else{
            return R.fail();
        }
    }

    @Override
    public R delete(int v_id) {
        if (dao.delete(v_id)>0){
            return R.ok();
        }else{
            return R.fail();
        }
    }

    @Override
    public PageBean selectPage(String vip_act, int page, int limit) {
        if (StringUtil.isNotEmpty(vip_act)){
            vip_act="%"+vip_act+"%";
        }
        int start=(page-1)*limit;

        return PageBean.ok(dao.selectCount(vip_act),dao.selectPage(vip_act,start,limit));


    }
}
